<?php

/**
 * This is the model class for table "data_episode".
 *
 * The followings are the available columns in table 'data_episode':
 * @property string $id
 * @property string $name
 * @property string $en_name
 * @property string $fid
 * @property string $description
 * @property integer $links_num
 * @property string $order
 * @property integer $active
 */
class Server extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Episode the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'data_server';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, fid', 'required'),
			array('links_num, active', 'numerical', 'integerOnly'=>true),
			array('name, en_name', 'length', 'max'=>200),
			array('fid, order', 'length', 'max'=>20),
			array('description', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, en_name, fid, description, links_num, order, active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'film'=>array(self::MANY_MANY,'Film','data_server(id,fid)','select'=>'id,title'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'en_name' => 'Url',
			'fid' => 'Fid',
			'description' => 'Description',
			'links_num' => 'Links Num',
			'order' => 'Order',
			'active' => 'Active',
			'film'=>'Film',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		
		$criteria=new CDbCriteria;
		$fid=Yii::app()->request->getParam('fid',0);
		if($fid!=0){
			$this->fid=$fid;
		}
		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('en_name',$this->en_name,true);
		$criteria->compare('fid',$this->fid);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('links_num',$this->links_num);
		$criteria->compare('order',$this->order,true);
		$criteria->compare('active',$this->active);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
		        'defaultOrder'=>'t.order ASC',
		    ),
		));
	}
}